package com.wanxi.controller;

import com.wanxi.dto.ResultDTO;
import com.wanxi.service.RoleService;
import com.wanxi.vo.RoleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/role")
public class RoleController {
    @Autowired
    RoleService roleService;

    @GetMapping("/findAll")
    @PreAuthorize("hasAuthority('updatePermission')")
    public ResultDTO findAllRole(){
        return roleService.findAllRole();
    }

    @PutMapping("/add")
    @PreAuthorize("hasAuthority('updatePermission')")
    public ResultDTO addRole(RoleVO roleVO){
        return roleService.addRole(roleVO);
    }

    @DeleteMapping("/delete")
    @PreAuthorize("hasAuthority('updatePermission')")
    public ResultDTO deleteRole(RoleVO roleVO){
        return roleService.deleteRole(roleVO);
    }

    @PostMapping("/findById")
    @PreAuthorize("hasAuthority('updatePermission')")
    public ResultDTO findRoleById(RoleVO roleVO){
        return roleService.findRoleById(roleVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('updatePermission')")
    public ResultDTO updateRole(RoleVO roleVO){
        return roleService.updateRole(roleVO);
    }
}
